package com.boomsecret.juc.locks;

/**
 * @author wangjinliang on 2019/1/18.
 */
public class SynchronizedThreadDemo {

    public static void main(String[] args) {
        ThreadA ta = new ThreadA("ta");
        synchronized(ta) {
            try {
                System.out.println(Thread.currentThread().getName()+" start ta");
                ta.start();

                System.out.println(Thread.currentThread().getName()+" block");
                ta.wait();

                System.out.println(Thread.currentThread().getName()+" continue");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    static class ThreadA extends Thread{
        public ThreadA(String name) {
            super(name);
        }

        @Override
        public void run() {
            synchronized (this) {
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+" wakeup others");
                notify();
            }
        }
    }
}